package com.polaris.live.popup

import android.content.Context
import android.view.ViewGroup
import com.bumptech.glide.Glide
import com.lxj.xpopup.core.BottomPopupView
import com.polaris.live.common.util.AppCodeUtils
import com.polaris.live.common.util.NavigationBarUtils
import com.polaris.live.databinding.PopupVipBarrageWhatBinding
import com.polaris.live.utils.XPopupUtils
import com.polaris.live.utils.image.ImageUtils

/**
 * VipBarrageWhatPopup 弹幕说明
 *
 * @author Created by 天晴 on 2024/12/18/004 17:21
 */
class VipBarrageWhatPopup(
    context: Context,
    private val showGoVip: Boolean,
    private val goVip: (() -> Unit)? = null,
) : BottomPopupView(context) {

    private lateinit var mBinding: PopupVipBarrageWhatBinding

    override fun getImplLayoutId(): Int {
        return com.polaris.live.R.layout.popup_vip_barrage_what
    }

    private val img1 = "static/barrage/explain_1.png"
    private val img2 = "static/barrage/explain_2.png"

    override fun onCreate() {
        super.onCreate()
        mBinding = PopupVipBarrageWhatBinding.bind(popupImplView)

        if (AppCodeUtils.isAR()) {
            mBinding.icBack.scaleX = -1f
        }
        val lp = mBinding.bottom.layoutParams as ViewGroup.LayoutParams
        lp.height = NavigationBarUtils.getNavigationBarHeight(context)
        mBinding.bottom.layoutParams = lp

        Glide.with(mBinding.img1)
            .load(ImageUtils.imgPath(img1))
            .into(mBinding.img1)
        Glide.with(mBinding.img2)
            .load(ImageUtils.imgPath(img2))
            .into(mBinding.img2)
        mBinding.goVip.visibility = if (showGoVip) VISIBLE else GONE

        mBinding.icBack.setOnClickListener {

            dismiss()
        }
        mBinding.goVip.setOnClickListener {

            dismiss()
            goVip?.invoke()
        }
    }

    companion object {

        fun showPop(
            context: Context,
            showGoVip: Boolean,
            goVip: (() -> Unit)? = null,
        ) {
            XPopupUtils.showPopup(
                VipBarrageWhatPopup(context, showGoVip, goVip),
                {
                    hasShadowBg(true)
                },
            )
        }
    }
}